<?php

require_once   BaseUtil::getModulePath("base")  .  '/validate/Unique.php';

class Department_DepartmentForm extends Zend_Form {
	public function __construct($options = null) {

        //for i18n
        $translate = Zend_Registry::get('Zend_Translate');
		if(!empty($options['id'])){
            $this->setAction(HttpUtil::getUrl("department", "subedit"));
		}else{
			$this->setAction(HttpUtil::getUrl("department", "subadd"));
		}
//		$this->setMethod('post');
//		$this->setName ( 'add' );

		$name = new Zend_Form_Element_Text('name');
		if(!empty($options['id'])){
			$id = new Zend_Form_Element_Hidden('department_id');
			$id->setValue($options['id']);
            $this->addElement($id);
		}
		$name->setLabel($translate->_('deName'));

		if(!empty($options['name'])){
			$name->setValue($options['name']);
		}
        $name->addFilter("StringTrim");
        $name->setRequired(true);
        //unique validate
        $validUnique = new MyValid_Unique();
        //$validUnique->setTranslator($translate);
        $validUnique->setTableName('departments');
        $validUnique->setFieldName('name');
        if(!empty($options['id'])){
            $validUnique->setId($options['id']);
        }
        $name->addValidator($validUnique);


		$this->addElements(array($name));

        $this->setElementDecorators(array(
            'ViewHelper',
            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_element")),
        ));

//            $name->setDecorators(array(
//            'ViewHelper',
//            array('Errors', array("class" => "input_errors")),
//            array(array('data' => 'HtmlTag'), array('tag' => 'div',"class" => "form_input_div")),
//            array('Label', array('tag' => 'div',"class"=>'form_input_label')),
//            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_line_div")),
//        ));

//        $this->setDecorators(array(
//            'FormElements',
//            array('HtmlTag', array('tag' => 'div',"class"=>"form_div")),
//            'Form',
//        ));

	}
}